/**
 * Created by HP on 2017/8/14.
 * 查看笔记内容
 */


function logout(){
	window.location.href="/i/noteuser/noteUser/noteUser";
}

window.onload=function(){
    var mytitle=document.getElementById("note_title");
    var mydate=document.getElementById("date");
    var mytext=document.getElementById("article");
    //var back_button=document.getElementById("back");
    var edit_button=document.getElementById("edit");

   
    var note_id=getCookie("noteId");

    var request=new XMLHttpRequest();
    request.open("POST","/i/note/note/getNote",true);
    request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    var message="noteId="+note_id;
    request.onreadystatechange=function(){
        if(request.readyState==4)
        {
            if(request.status==200)
            {
                var data=JSON.parse(request.responseText);
                if(data.result==1)
                {
                    alert("请求成功");
                    document.getElementById("note_title").innerHTML=data.title;
					document.getElementById("date").innerHTML=data.updateTime;
					document.getElementById("article").innerHTML=data.text;
                }
            }
            else{
                alert("请求错误"+request.status);
            }
        }
    }
    request.send(message);

    /*
    back_button.onclick=function(){
        window.location.href="/i/noteuser/noteUser/toMain";
    }
     */
    edit_button.onclick=function(){
	    window.location.href="/i/noteuser/noteUser/toeditLast";
    }
    function setCookie(cname,cvalue,exdays){
        var d = new Date();
       d.setTime(d.getTime()+(exdays*24*60*60*1000));
       var expires = "expires="+d.toGMTString();
       document.cookie = cname + "=" + cvalue + "; " + expires;
       } 
       
       
    function getCookie(cname){
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) 
          {
          var c = ca[i].trim();
          if (c.indexOf(name)==0) return c.substring(name.length,c.length);
         }
        return "";
        } 
}

